//
//  TabBarViewController.m
//  AddressBook
//
//  Created by mac on 2017/8/25.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "TabBarViewController.h"
#import "CompanyViewController.h"
#import "LocalAddressTableViewController.h"
#import "MyViewController.h"

@interface TabBarViewController ()

@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSArray *imageArray;
@property (nonatomic, strong) NSArray *seleImageArray;
@property (nonatomic, strong) NSMutableArray <UINavigationController *> *viewController;

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.viewController = [NSMutableArray array];
    [self addChildVCs];
//    self.titleArray = @[@"",@"",@"我的"];
//    self.imageArray = @[@"main_btn_company_contract_g",@"main_btn_local_contract_g",@"main_btn_my_g"];
//    self.seleImageArray = @[@"main_btn_company_contract",@"main_btn_local_contract",@"main_btn_my"];
}

-(void)addChildVCs{
    [self addChildVCTitle:@"公司通讯录" ClassName:@"CompanyViewController" normalImageName:@"main_btn_company_contract_g" selectedImageName:@"main_btn_company_contract"];
    
    [self addChildVCTitle:@"本地通讯录" ClassName:@"LocalAddressTableViewController" normalImageName:@"main_btn_local_contract_g" selectedImageName:@"main_btn_local_contract"];
    [self addChildVCTitle:@"我的" ClassName:@"MyViewController" normalImageName:@"main_btn_my_g" selectedImageName:@"main_btn_my"];
    
    // 设置标签栏的viewControllers
    self.viewControllers = self.viewController;

}

- (void)addChildVCTitle:(NSString *)title ClassName:(NSString *)className normalImageName:(NSString *)normalImageName selectedImageName:(NSString *)selectedImageName {
    
    Class class = NSClassFromString(className);
    UIViewController *vc = [[class alloc] init];
    
    vc.view.backgroundColor = [UIColor whiteColor];
    
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:normalImageName] selectedImage:[UIImage imageNamed:selectedImageName]];
    
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:vc];
//    navc.tabBarController.tabBar.hidden=YES;
//    navc.hidesBottomBarWhenPushed=YES;
    // 导航标题
    vc.navigationItem.title = title;
    
    // 导航不透明
    navc.navigationBar.translucent = NO;
    
    // 导航栏背景
    navc.navigationBar.barTintColor = MainColor;
    
    // 导航标题字体颜色
    [navc.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor whiteColor]}];
    
//    navc.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(action_popItem)];
    // 返回按钮的颜色
    [navc.navigationBar setTintColor:[UIColor whiteColor]];
    
    [self.viewController addObject:navc];
}

- (void)action_popItem {
    [self.navigationController popViewControllerAnimated:YES];
}




@end
